package com.air.antispider.stream.dataprocess.businessprocess

import com.air.antispider.stream.common.bean.{QueryRequestData, _}
import com.air.antispider.stream.dataprocess.constants.TravelTypeEnum.TravelTypeEnum


//TODO:数据打包,将散乱的数据封装为ProcessedData
/**
  * 数据打包,将散乱的数据封装为ProcessedData
  */
object DataPackage {
  def dataPackage(sourceData: String, requestMethod: String, request: String, remoteAddr: String,
                  httpUserAgent: String, timeIso8601: String, serverAddr: String,
                  isFreIP: Boolean, requestType: RequestType, travelType: TravelTypeEnum,
                  cookieValue_JSESSIONID: String, cookieValue_USERID: String,
                  queryRequestData: Option[QueryRequestData],
                  bookRequestData: Option[BookRequestData],
                  httpReferrer: String): ProcessedData = {

    //用于封装核心请求信息：飞行时间、目的地、出发地
    //飞行时间
    var flightDate:String = ""
    //目的地
    var depcity :String= ""
    //出发地
    var arrcity :String = ""
    queryRequestData match {
      case Some(queryRequest) => {
        flightDate = queryRequest.flightDate
        depcity = queryRequest.depCity
        arrcity = queryRequest.arrCity
      }
      case None =>
        //如果查询没有匹配上，看看预定能不能匹配上
        bookRequestData match {
          case Some(bookRequest) => {
            flightDate = bookRequest.flightDate.mkString
            depcity = bookRequest.depCity.mkString
            arrcity = bookRequest.arrCity.mkString
          }
          case None =>
        }
    }

    //构建核心请求参数
    val requestParams = CoreRequestParams(flightDate, depcity, arrcity)

    ProcessedData(sourceData, requestMethod, request, remoteAddr, httpUserAgent, timeIso8601,
      serverAddr, isFreIP, requestType, travelType, requestParams, cookieValue_JSESSIONID,
      cookieValue_USERID, queryRequestData, bookRequestData, httpReferrer)
  }

}
